package OnlineLibrary.managers;

import java.util.Properties;

import org.apache.log4j.Logger;
import org.omg.CORBA.ORB;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextHelper;
import be.fundp.info.util.logging.MyLogger;
import Util.Util;

public class Mgr {
	protected ORB orb;
	protected NamingContext context;
	protected String ip;
	protected String port;
	protected String[] ids;
	protected Logger logger;
	private final String log4j = "log4j.properties";
	protected final static String prop = "OnlineLibrary.properties";
	
	public Mgr(){
		if(!MyLogger.isConfigured())
			MyLogger.initLogger(log4j);
		logger = MyLogger.getLogger(Class.class);

		ip = Util.getPropertiesAttribute(prop, "ip");
		port = Util.getPropertiesAttribute(prop, "port");
		//retrieve the identifier of each book store
		ids = Util.getPropertiesList(prop, "BS");
		
	
		Properties props = new Properties();
		props.put("org.omg.CORBA.ORBInitialHost", ip);
		props.put("org.omg.CORBA.ORBInitialPort", port);

		// initialize ORB
		orb = ORB.init(new String[] { "-ORBInitialPort", port, "-ORBInitiaHost", ip }, props);

		// retrieve Naming service
		org.omg.CORBA.Object objNameService = orb.string_to_object("corbaloc:iiop:" + ip + ":" + port + "/NameService");
		context = NamingContextHelper.narrow(objNameService);
		
	}
	
	public static String getPropertiesFile(){
		return prop;
	}
	

}
